// loginController
angular.module("loginApp").controller('loginController', function($scope, $http) {
    // 表单验证
    $scope.checkUsername = function() {
        if ($scope.Username) {
            $scope.usernameStyle = false;
        } else {
            $scope.usernameStyle = true;
            $scope.usernameErrorMsg = "请输入用户名";
        };
    };
    $scope.checkPassword = function() {
        if ($scope.Password) {
            $scope.passwordStyle = false;
        } else {
            $scope.passwordStyle = true;
            $scope.passwordErrorMsg = "请输入密码";
        };
    };

    $scope.login = function() {
        $scope.loginData = {
            username: $scope.Username,
            password: $scope.Password
        };
        $http.post(dbLoginURL + "login", $scope.loginData).success(function(data, status) {
            if (data.state) {
                window.location.href = "/";
            } else {
                console.log(data.msg);
            }

        }).error(function(data, status) {
            alert('服务器错误：' + status);
        });
    };
});

// IndexController
angular.module('mainApp').controller('IndexController', ['$scope', 'IndexService', function($scope, IndexService){
    IndexService.menu().success(function (res) {
        $scope.navigation = res.navigation;
    });

    $scope.currentMenu = function(index) {
        $scope.menuIndex = index;
    };
}]);